package cn.edu.scau.cmi.wangzm.singleton;

import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class SingletonController {

    @FXML
    private ResourceBundle resources;
    @FXML
    private URL location;
    @FXML
    private TextField inputField;
    @FXML
    private Button button2;
    @FXML
    private TextArea outputAreaTwo;
    @FXML
    private TextArea outputAreaOne;
    @FXML
    private Button button1;
    private int key=1;
    private String name=null;
    private static ArrayList<Marshal> arrayLists = new ArrayList<>(10);
    @FXML
    void handleOk1(ActionEvent event) {
    	if(key==1) {
    	name=inputField.getText();
    	key=0;
    	}
    	Chairman chairman=new Chairman(name);
        outputAreaOne.appendText(chairman.toString()+"\n");
    }

    @FXML
    void handleOk2(ActionEvent event) {
    	String name=inputField.getText();
    	Marshal marsahal = MarshalPool.getMarsahal();
		if(marsahal==null) {
			outputAreaTwo.appendText("已经创建十个对象"+"\n");
		}else {
			outputAreaTwo.appendText(name+super.toString()+"\n");
		}
    }

    @FXML
    void initialize() {
        assert inputField != null : "fx:id=\"inputField\" was not injected: check your FXML file 'Singleton.fxml'.";
        assert button2 != null : "fx:id=\"button2\" was not injected: check your FXML file 'Singleton.fxml'.";
        assert outputAreaTwo != null : "fx:id=\"outputAreaTwo\" was not injected: check your FXML file 'Singleton.fxml'.";
        assert outputAreaOne != null : "fx:id=\"outputAreaOne\" was not injected: check your FXML file 'Singleton.fxml'.";
        assert button1 != null : "fx:id=\"button1\" was not injected: check your FXML file 'Singleton.fxml'.";

    }
}
